package com.haopt.learn;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author haopt
 * @version 1.0
 * @ClassName Demo
 * @Description TODO
 * @date 2021/5/9 22:41
 */
public class Demo {
    public static void main(String[] args) {
        //当前线程池中，核心线程个数为10
        ScheduledExecutorService service = Executors.newScheduledThreadPool(10);
        service.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行了任务1" + new Date());
            }
            //run方法等1秒执行。每5秒执行一次。TimeUnit.SECONDS时间单位
        }, 1, 5, TimeUnit.SECONDS);

    }
}
